#!/bin/bash
db=MySQL
# 设置不同的ddl buffer size
for dbp in 64 128 256 512 1024
do
exec 3>&1 4>&2 1>> parallel-index-build-${dbp}m.log 2>&1

# 循环10次
for i in $(seq 1 10)
do
 echo "$db cycle $i"
 mysql -N -s -q -f -S./$db/mysql.sock -e "set global innodb_ddl_buffer_size=$dbp*1024*1024" test > /dev/null 2>&1
 mysql -f -S./$db/mysql.sock -e "select @@global.innodb_ddl_buffer_size" test
 mysql -N -s -q -f -S./$db/mysql.sock -e "alter table t1 drop index i1, drop index i2;" test > /dev/null 2>&1
 sleep 5
 time mysql -N -s -q -f -S./$db/mysql.sock -e "alter table t1 add index i1(k), add index i2(pad);" test
 echo ""
 echo ""
 sleep 5
done

# 调整ddl threads = 8
exec 3>&1 4>&2 1>> parallel-index-build-${dbp}m-8th.log 2>&1
for i in $(seq 1 10)
do
 echo "$db cycle $i"
 mysql -N -s -q -f -S./$db/mysql.sock -e "set global innodb_ddl_threads=8" test > /dev/null 2>&1
 mysql -f -S./$db/mysql.sock -e "select @@global.innodb_ddl_threads" test
 mysql -N -s -q -f -S./$db/mysql.sock -e "alter table t1 drop index i1, drop index i2;" test > /dev/null 2>&1
 sleep 5
 time mysql -N -s -q -f -S./$db/mysql.sock -e "alter table t1 add index i1(k), add index i2(pad);" test
 echo ""
 echo ""
 sleep 5
done

# 恢复 ddl threads=4
 mysql -N -s -q -f -S./$db/mysql.sock -e "set global innodb_ddl_threads=4" test > /dev/null 2>&1
 mysql -f -S./$db/mysql.sock -e "select @@global.innodb_ddl_threads" test
done